package com.sx.sx1.task;


import com.sx.sx1.service.SyncYBXService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;



@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SyncQuestion {

      /*
sftmphost: 192.168.100.107
sftpport: 22
sftpusername: king
sftppassword: 123456
sftpremotePath: /picclife/nas/000100/east    #/picclife/nas/000100/east/1320   1320 是目录名，也是任务号，下面存放问题数据文件
#  sftp本地路径ruoyi.profle.ybx下

 */

    @Value("${sftmphost}")
    private String sftmphost;

    @Value("${sftpport}")
    private int sftpport;

    @Value("${sftpusername}")
    private String sftpusername;

    @Value("${sftppassword}")
    private String sftppassword;
    @Value("${sftpremotePath}")
    private String sftpremotePath;


    @Autowired
    private SyncYBXService syncYBXService;
    //测试的
//    @Scheduled(cron = "0 0/2 * * * ?")
    @Scheduled(cron = "0 58 14 1-31 * ?")
    public void sycybxquestiondata() {


        try {

            //传输文件
            List<Integer> syncybxids = Arrays.asList(1319,1320);
            List<Integer> list = new ArrayList<>();
            if(syncybxids!=null && syncybxids.size() >0) {

                //----sftp传输文件开始
                for (Integer jobid : syncybxids) {

                    String remoteFiledir = sftpremotePath+"/"+ jobid;  //远程目录，直接去取

                    Integer ret =  syncYBXService.readerRemoteDirAndFile(remoteFiledir,jobid);
                    if(ret !=null){
                        list.add(ret);
                    }
                }
            }

            System.out.println(list);

            //读取文件，插入到高斯和ORACLE的问题数据表
            // List<Integer> list = syncYBXService.syncybxquestiondata();

            //从oraclec获取问题数据的清单，更新east_error_list_ybx表的清单字段
           // syncYBXService.syncYBXQSqingdan(list, get46table());
        } catch (Exception e) {
            e.printStackTrace();

        }
    }

}
